<template>
  <div>
    <el-table :data="competitiveTableData" stripe size="mini" style="width: 100%">
      <el-table-column prop="locationName" label="比赛场地" :width="70" align="center" />
      <el-table-column prop="phaseName" label="进程" :width="70" align="center" />
      <el-table-column prop="unitCode" label="场次号" :width="100" align="center" />
      <el-table-column prop="eventName" label="比赛项目" :min-width="200" />
      <el-table-column prop="statusName" label="状态" :width="70" align="center" />
      <el-table-column :width="320">
        <template slot="header">
          <div class="person_wina">青方</div>
          <div class="person_vs" />
          <div class="person_winb">红方</div>
        </template>
        <template slot-scope="{ row }">
          <div class="person_wina">
            <PersonalImage v-if="row.registerTypeCodeA == 'I'" :imgurl="row.imagePathA" :imgheight="'50px'" />
            <img
              v-else
              :src="getStaticFileUrl(row.imagePathA)"
              class="person_img"
              @error="errorPhoto"
            >
            <div class="gl_mt_5">
              <div v-if="row.registerTypeCodeA == 'I'">
                <el-popover placement="top" width="300" trigger="hover" :content="row.playerNameA">
                  <div slot="reference" class="gl_ellipsis">{{ row.playerNameA ? row.playerNameA : '- -' }}</div>
                </el-popover>
                <el-popover placement="bottom" width="300" trigger="hover" :content="row.delegationNameA">
                  <div slot="reference" class="gl_ellipsis">{{ row.delegationNameA ? row.delegationNameA : '- -' }}</div>
                </el-popover>
              </div>
              <diV v-else>
                <el-popover placement="bottom" width="300" trigger="hover" :content="row.delegationNameA">
                  <div slot="reference" class="gl_ellipsis">{{ row.delegationNameA ? row.delegationNameA : '- -' }}</div>
                </el-popover>
                <el-popover placement="bottom" width="300" trigger="hover" :content="row.memberNamesA">
                  <div slot="reference" class="gl_ellipsis">{{ row.memberNamesA ? row.memberNamesA : '- -' }}</div>
                </el-popover>
              </diV>
              <div class="gl_color_error gl_ml_10">{{ row.combatScoreA }}</div>
            </div>
          </div>
          <div class="person_vs">VS</div>
          <div class="person_winb">
            <PersonalImage v-if="row.registerTypeCodeB == 'I'" :imgurl="row.imagePathB" :imgheight="'50px'" />
            <img
              v-else
              :src="getStaticFileUrl(row.imagePathB)"
              class="person_img"
              style="margin-left: 80px"
              @error="errorPhoto"
            >
            <div class="gl_mt_5">
              <div v-if="row.registerTypeCodeB == 'I'">
                <el-popover placement="top" width="300" trigger="hover" :content="row.playerNameB">
                  <div slot="reference" class="gl_ellipsis">{{ row.playerNameB ? row.playerNameB : '- -' }}</div>
                </el-popover>
                <el-popover placement="bottom" width="300" trigger="hover" :content="row.delegationNameB">
                  <div slot="reference" class="gl_ellipsis">{{ row.delegationNameB ? row.delegationNameB : '- -' }}</div>
                </el-popover>
              </div>
              <div v-else>
                <el-popover placement="bottom" width="300" trigger="hover" :content="row.delegationNameB">
                  <div slot="reference" class="gl_ellipsis">{{ row.delegationNameB ? row.delegationNameB : '- -' }}</div>
                </el-popover>
                <el-popover placement="bottom" width="300" trigger="hover" :content="row.memberNamesB">
                  <div slot="reference" class="gl_ellipsis">{{ row.memberNamesB ? row.memberNamesB : '- -' }}</div>
                </el-popover>
              </div>
              <div class="gl_color_error gl_mr_10">{{ row.combatScoreB }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="" label="比赛结果" :min-width="100">
        <template slot-scope="{ row }">
          <span v-if="row.winnerPosition == 1">青方{{ row.winTypeName }}</span>
          <span v-if="row.winnerPosition == 2">红方{{ row.winTypeName }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import defaultPersonImg from '@/assets/images/face_default.png';
import PersonalImage from '@/components/PersonalImage/index';
export default {
  name: 'Competitive',
  components: {
    PersonalImage
  },
  props: {
    competitiveTableData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      defaultPersonImg: defaultPersonImg
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict
    })
  },
  created() {
    this.getDict();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    // 获取静态图片地址
    getStaticFileUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    errorPhoto() {
      const img = event.srcElement;
      img.src = this.defaultPersonImg;
    }
  }
};
</script>
<style scoped>
.person_wina {
  display: inline-block;
  vertical-align: middle;
  width: 128px;
  text-align: left;
}
.person_vs {
  display: inline-block;
  vertical-align: middle;
  width: 39px;
  line-height: 50px;
  text-align: center;
  font-weight: bold;
}
.person_winb {
  display: inline-block;
  vertical-align: middle;
  width: 130px;
  text-align: right;
}
.person_img {
  max-width: 50px;
  max-height: 50px;
  display: block;
}
</style>
